package org.argeproje.resim.proc;

import java.util.ArrayList;
import java.util.HashMap;



public class ConnectionRule{
	protected HashMap<Integer, ArrayList<Class> > _inTypes = new HashMap<Integer, ArrayList<Class> >();
	protected ArrayList<Class> _outTypes = new ArrayList<Class>();
	public static boolean validConnection(ConnectionRule srcConn, int srcOutIndex, 
			ConnectionRule dstConn, int dstInIndex){

		boolean result = dstConn.inTypeMatch(srcConn.getOutType(srcOutIndex),
				dstInIndex);
		return result;
	}
	public int getNoInputs(){
		return _inTypes.size();
	}
	public int getNoOutputs(){
		return _outTypes.size();
	}
	public void addInType(Class c, int inputIndex){
		Integer index = new Integer(inputIndex);
		if(!_inTypes.containsKey(index)){
			_inTypes.put(index, new ArrayList<Class>());
		}
		_inTypes.get(index).add(c);
	}
	public void addOutType(Class c){
		_outTypes.add(c);
	}
	protected Class getOutType(int index){
		return _outTypes.get(index);
	}
	protected boolean inTypeMatch(Class c, int index){
		boolean result = false;
		if(_inTypes.get(index).contains(c)){
			result = true;
		}
		return result;
	}
	protected boolean outTypeMatch(Class c, int index){
		boolean result = false;
		if(c == _outTypes.get(index)){
			result = true;
		}
		return result;
	}

}
